<?php
/**
 * Created by JetBrains PhpStorm.
 * User: fenglangyj
 * DateTime:   2013-10-11 11:10:37
 * To change this template use File | Settings | File Templates.
 */
class soft_model extends  SDF_Model
{
    var $title = '';
    var $content = '';
    var $date = '';
    public $soft_id;  //软件ID
    public function __construct(){
        $this->db = $this->load->database('default',true);
        parent::__construct();
        $this->load->helper('cookie');
        $this->soft_id = $this->input->cookie('soft_id');
    }

    
      /**
     * 获取软件列表
     * @return array
     */
    public function get_soft_list(){
        $soft_arr = $this->db->select('soft_id,name')->get_where('soft')->result_array();
        $list = array();
        foreach($soft_arr as $user){
            $list[$user['soft_id']] = $user;
        }
        return $list;
    }
        
      /**
     * 获取软件名列表
     * @return array
     */
    public function get_soft_names(){
        $soft_arr = $this->db->select('soft_id,name')->get_where('soft')->result_array();
        $soft_names = array();
        foreach($soft_arr as $user){
            $soft_names[$user['soft_id']] = $user['soft_id'].'| '.$user['name'];
        }
        return $soft_names;
    }
        
    /**
     * 获取软件版本名列表
     * @return array
     */
    public function get_version_names(){
        $soft_arr = $this->db->select('id,soft_id,version')->get_where('soft_version')->result_array();
        $soft_names = array();
        foreach($soft_arr as $user){
            $soft_names[$user['id']] =$user['version'];
        }
        return $soft_names;
    }
    /**
     * 获取地区名列表(用于取出当前id的名称)
     * @return array
     */
    public function get_region_nick(){
        $region = array();
        $region[0]='其它';
        $region_arr = $this->db->select('region_id,region_name')->get_where('region')->result_array();
        foreach ($region_arr as $v){
            $region[$v['region_id']] = $v['region_name'];
        }

        return $region;
    }

    /**
     * 获取渠道列表
     * @return array
     */
    public function get_channel_account(){
    	$channel_account = array();
        $channel_account_arr = $this->db->select('id,username,nick,principald_id,media,cooperation')->get_where('channel_account',array('soft_id'=>$this->soft_id))->result_array();
        foreach ($channel_account_arr as $k=>$v){
        	$channel_account[$v['id']] = $v;
        }
        unset($channel_account_arr);      
        return $channel_account;
    }
    /**
     * 获取渠道信息列表
     * @return array
     */
    public function get_channel_names(){
        $channel_arr = $this->db->select('id,username,nick,principald_id,media,cooperation')->get_where('channel_account',array())->result_array();
        return $channel_arr;
    }


    /**
     * 获取地区名列表
     * @return array
     */
    public function get_region_names(){
        $region[0]=array('region_id'=>0,'region_name'=>'其它');
        $region_arr = $this->db->select('region_id,region_name')->get_where('region',array('region_type'=>1))->result_array();
        foreach ($region_arr as $k=>$v){
        	$region[$v['region_id']] = $v;
        }
        unset($region_arr);
        return $region;
    }


    /**
     * 获取资源实体
     * @return array
     */
    public function Get_Entitys($entity_type_id=''){
        $entity = array();
        $this->db->dbprefix = 'eav_';
		if($entity_type_id){
        $entity_arr = $this->db->select('entity_id,title')->order_by('entity_id')->get_where('entity',array('entity_type_id'=>$entity_type_id,'soft_id'=>get_cookie('soft_id')))->result_array();}else{
		 $entity_arr = $this->db->select('entity_id,title')->order_by('entity_id')->get_where('entity',array('soft_id'=>get_cookie('soft_id')))->result_array();}
        foreach ($entity_arr as $v){
            $entity[$v['entity_id']] = $v;
        }
        unset($entity_arr);
        return $entity;
    }

    /**
     * 获得指定软件详细信息
     * 
     */
    function get_soft_info($softid)
    {
    	$this->db->where(array('soft_id'=> $softid));
    	$this->db->from('soft');
    	$query = $this->db->get();
    	$list = $query->result_array();
    	
    	return $list[0];
    }



    /**
     * 获取软件名列表1
     * @return array
     */
    public function get_softs_names(){
        $arr = $this->db->select('soft_id,name')->get_where('soft',array())->result_array();
        foreach ($arr as $v){
        	$soft_arr[$v['soft_id']] = $v;
        }
        unset($arr);
        return $soft_arr;
    }



    /**
     * 获取版本列表
     * @return array
     */
    public function get_version_list($where = array()){
    	$arr = $this->db->select('*')->get_where('soft_version',$where)->result_array();
        return $arr;
    }




    /**
     * 获取动作例表
     * @return array
     */
    public function Get_motion($soft_id=0){
       $motion_arr = $this->db->select('id,m_name,parent_id')->order_by('id')->get_where('motion',array('soft_id'=>$soft_id))->result_array();
       // $motion_arr = $this->db->select('id,m_name,parent_id')->order_by('id')->get_where('motion')->result_array();
        $m_arr = array();
        foreach($motion_arr as $row){
            $m_arr[$row['parent_id']][] = $row;

        }
        return $m_arr;
    }

    /**
     * 获取动作名称
     * @return array
     */
    public function Get_motion_name($motion_id){
        $motion_name = $this->db->select('id,m_name')->order_by('id')->get_where('motion',array('id'=>$motion_id))->row_array();
        return $motion_name;
    }

    /**
     * 获取安装软件例表
     * @return array
     */
    public function Get_software($soft_id){
        $software = $this->db->select('id,software_name,course_flag,icon,keywords')->order_by('id')->get_where('software',array('soft_id' => $soft_id))->result_array();
        return $software;
    }

    /**
     * 获取动作辅助字段名
     * @return array
     */
    public function get_auxiliary_names($motion_id){
        $v_name = $this->db->select('id,motion_flag,v1,v2,v3')->get_where('motion',array('id'=>$motion_id))->result_array();
        return $v_name;
    }


    /**
     * 获取动作辅助值对应栏目中文名(数据字典)
     * @return array
     */
    public function get_auxiliary_dictionary(){
        $list = $this->db->select('id,motion_flag,flag_name,flag_v')->get_where('dictionary',array('soft_id'=>get_cookie('soft_id')))->result_array();
        $v_arr = array();
        foreach($list as $row){
            $v_arr[$row['flag_v']][$row['motion_flag']] = $row['flag_name'];
        }
        return $v_arr;
    }

}
